from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-22 14:10:54.517570
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 22, Apr, 2021
Time: 14:10:58
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.6903
Nobs: 269.000 HQIC: -48.4100
Log likelihood: 3230.85 FPE: 5.83697e-22
AIC: -48.8930 Det(Omega_mle): 4.20262e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.433341 0.122301 3.543 0.000
L1.Burgenland 0.084175 0.060850 1.383 0.167
L1.Kärnten -0.220523 0.053513 -4.121 0.000
L1.Niederösterreich 0.090604 0.131007 0.692 0.489
L1.Oberösterreich 0.218860 0.125453 1.745 0.081
L1.Salzburg 0.264990 0.069446 3.816 0.000
L1.Steiermark 0.114754 0.088451 1.297 0.195
L1.Tirol 0.116924 0.060845 1.922 0.055
L1.Vorarlberg -0.034144 0.056107 -0.609 0.543
L1.Wien -0.059083 0.113377 -0.521 0.602
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.465208 0.142415 3.267 0.001
L1.Burgenland 0.005482 0.070858 0.077 0.938
L1.Kärnten 0.329036 0.062314 5.280 0.000
L1.Niederösterreich 0.088169 0.152554 0.578 0.563
L1.Oberösterreich -0.063197 0.146086 -0.433 0.665
L1.Salzburg 0.222267 0.080868 2.749 0.006
L1.Steiermark 0.097668 0.102998 0.948 0.343
L1.Tirol 0.136495 0.070852 1.926 0.054
L1.Vorarlberg 0.154606 0.065334 2.366 0.018
L1.Wien -0.424719 0.132023 -3.217 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.278133 0.061892 4.494 0.000
L1.Burgenland 0.097093 0.030794 3.153 0.002
L1.Kärnten -0.015962 0.027081 -0.589 0.556
L1.Niederösterreich 0.075329 0.066298 1.136 0.256
L1.Oberösterreich 0.284299 0.063488 4.478 0.000
L1.Salzburg 0.021175 0.035144 0.603 0.547
L1.Steiermark -0.004062 0.044762 -0.091 0.928
L1.Tirol 0.070481 0.030792 2.289 0.022
L1.Vorarlberg 0.081826 0.028394 2.882 0.004
L1.Wien 0.114955 0.057376 2.004 0.045
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.214089 0.059462 3.600 0.000
L1.Burgenland 0.024063 0.029585 0.813 0.416
L1.Kärnten 0.009233 0.026018 0.355 0.723
L1.Niederösterreich 0.056030 0.063695 0.880 0.379
L1.Oberösterreich 0.399550 0.060995 6.551 0.000
L1.Salzburg 0.082360 0.033764 2.439 0.015
L1.Steiermark 0.126444 0.043005 2.940 0.003
L1.Tirol 0.049510 0.029583 1.674 0.094
L1.Vorarlberg 0.083326 0.027279 3.055 0.002
L1.Wien -0.044725 0.055123 -0.811 0.417
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.486621 0.116481 4.178 0.000
L1.Burgenland 0.095580 0.057954 1.649 0.099
L1.Kärnten 0.010464 0.050967 0.205 0.837
L1.Niederösterreich 0.008516 0.124773 0.068 0.946
L1.Oberösterreich 0.130439 0.119483 1.092 0.275
L1.Salzburg 0.061429 0.066141 0.929 0.353
L1.Steiermark 0.057675 0.084242 0.685 0.494
L1.Tirol 0.208897 0.057950 3.605 0.000
L1.Vorarlberg 0.034054 0.053437 0.637 0.524
L1.Wien -0.086651 0.107982 -0.802 0.422
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199185 0.092243 2.159 0.031
L1.Burgenland -0.011890 0.045895 -0.259 0.796
L1.Kärnten -0.007707 0.040361 -0.191 0.849
L1.Niederösterreich -0.005143 0.098810 -0.052 0.958
L1.Oberösterreich 0.413840 0.094621 4.374 0.000
L1.Salzburg 0.015126 0.052378 0.289 0.773
L1.Steiermark -0.030793 0.066712 -0.462 0.644
L1.Tirol 0.161369 0.045891 3.516 0.000
L1.Vorarlberg 0.055985 0.042317 1.323 0.186
L1.Wien 0.215399 0.085512 2.519 0.012
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.231146 0.111939 2.065 0.039
L1.Burgenland 0.018677 0.055694 0.335 0.737
L1.Kärnten -0.072378 0.048979 -1.478 0.139
L1.Niederösterreich -0.075618 0.119908 -0.631 0.528
L1.Oberösterreich 0.024155 0.114824 0.210 0.833
L1.Salzburg 0.084046 0.063562 1.322 0.186
L1.Steiermark 0.328880 0.080957 4.062 0.000
L1.Tirol 0.459790 0.055690 8.256 0.000
L1.Vorarlberg 0.150054 0.051353 2.922 0.003
L1.Wien -0.144743 0.103771 -1.395 0.163
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.192467 0.133451 1.442 0.149
L1.Burgenland 0.038983 0.066398 0.587 0.557
L1.Kärnten -0.075325 0.058392 -1.290 0.197
L1.Niederösterreich 0.122863 0.142951 0.859 0.390
L1.Oberösterreich 0.020014 0.136891 0.146 0.884
L1.Salzburg 0.200264 0.075777 2.643 0.008
L1.Steiermark 0.117990 0.096515 1.223 0.222
L1.Tirol 0.060853 0.066392 0.917 0.359
L1.Vorarlberg 0.101972 0.061222 1.666 0.096
L1.Wien 0.226859 0.123713 1.834 0.067
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.548120 0.073096 7.499 0.000
L1.Burgenland -0.017761 0.036368 -0.488 0.625
L1.Kärnten -0.018542 0.031983 -0.580 0.562
L1.Niederösterreich 0.083132 0.078299 1.062 0.288
L1.Oberösterreich 0.308219 0.074980 4.111 0.000
L1.Salzburg 0.016857 0.041506 0.406 0.685
L1.Steiermark -0.043584 0.052865 -0.824 0.410
L1.Tirol 0.079997 0.036365 2.200 0.028
L1.Vorarlberg 0.110170 0.033533 3.285 0.001
L1.Wien -0.061361 0.067762 -0.906 0.365
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.154766 0.095974 0.166962 0.221347 0.077674 0.085432 0.008263 0.160749
Kärnten 0.154766 1.000000 0.050640 0.207155 0.182549 -0.060542 0.170379 0.024381 0.302998
Niederösterreich 0.095974 0.050640 1.000000 0.239758 0.081979 0.325836 0.143570 0.023808 0.302268
Oberösterreich 0.166962 0.207155 0.239758 1.000000 0.301401 0.262275 0.091178 0.060198 0.132223
Salzburg 0.221347 0.182549 0.081979 0.301401 1.000000 0.154096 0.059451 0.086591 0.013923
Steiermark 0.077674 -0.060542 0.325836 0.262275 0.154096 1.000000 0.101384 0.097140 -0.100694
Tirol 0.085432 0.170379 0.143570 0.091178 0.059451 0.101384 1.000000 0.156734 0.144490
Vorarlberg 0.008263 0.024381 0.023808 0.060198 0.086591 0.097140 0.156734 1.000000 -0.007212
Wien 0.160749 0.302998 0.302268 0.132223 0.013923 -0.100694 0.144490 -0.007212 1.000000